document.addEventListener("DOMContentLoaded", function() {
  if (testCopy()) {
    var colorSwatches = document.getElementsByClassName("lsg-color-swatch")
    for (var i = 0; i < colorSwatches.length; i++) {
      if (!colorSwatches[i].classList.contains("lsg-empty")) {
        colorSwatches[i].addEventListener("click", function(event) {
          if (event.target == this.children[0]) {
            selectElementRange(createDiv(this.children[0].innerHTML))
          }
          else {
            var copyHexColors = window.getComputedStyle(this, "::after").getPropertyValue("content")
            copyHexColors = copyHexColors.replace(/'|"/g, "")
            selectElementRange(createDiv(copyHexColors))
          }
        })
      }
    }
  }
})

function createDiv(copyHexColors) {
  var divCopy = document.createElement("div")
  divCopy.className = "lsg-remove"
  divCopy.setAttribute("style", "opacity: 0; position: absolute; top: -10000px")
  divCopy.appendChild(document.createTextNode(copyHexColors))
  document.body.appendChild(divCopy)
  return divCopy
}
